lapis = require "lapis"
import respond_to from require "lapis.application"

import Model from require "lapis.db.model"

class Article extends Model
    @table_name:=> "articles"

class extends lapis.Application
    "/": =>
        @html ->
            h1 My Articles
            ul ->
                for article in *Article\select!
                    li article.title .. "----" ..article.content

    "/new": =>
        article = Article\create{
            title: @params.title
            content: @params.content
        }
        

--class extends lapis.Application
--  -- @include "..applications.users"
--  [index: "/"]: =>
--    @html ->
--      a href: @url_for("login"), "Log in"
--
--  "/hello": =>
--    "xing wenju"
--
--  "/users/:name": => 
--    "Hello #{@params.name}"
--
--  "/things/*": => 
--     "Rest of the url: #{@params.splat}"
--
--  --[index: "/leaf"]: =>
--  -- @url_for "user_profile", name: "leaf"
--
--  [user_profile: "/user/:name"]: =>
--    "Hello #{@params.name}, go home: #{@url_for "index"}"
--
--  [create_account: "/create_account"]: respond_to {
--    GET: =>
--     "xing wenju"
--
--    POST: =>
--      create_user @params
--      redirect_to: @url_for "index"
--  }
--
--  "/edit_user/:id": respond_to {
--    before: =>
--      @user = Users\find @params.id
--      @write status: 404, "Not Found" unless @user
--
--    GET: =>
--      "Welcome " .. @user.name
--
--    POST: =>
--      @user\update @params.user
--      redirect_to: @url_for "index"
--  }
